﻿using System.Collections.ObjectModel;
using System.ComponentModel;
using TfsComLib.TfsBranchLib2;

namespace TfsBranchLib2.Model
{
    /// <summary>
    ///     Tfs list of directories attached to branch
    /// </summary>
    public class SourceControlFilter : ISourceControlFilter
    {
        /// <summary>
        ///     Базовая директория
        /// </summary>
        private ISourceControlBasePath basePath;

        /// <summary>
        ///     Список относительных путей, образующих фильтр.
        ///     Пути в списке не должны определять пересекающиеся множества.
        /// </summary>
        private ObservableCollection<string> subPathList;

        public SourceControlFilter(ISourceControlBasePath basePath)
        {
            if (basePath == null)
            {
                this.basePath = new SourceControlBasePath();
            }
            else
            {
                this.basePath = basePath;
            }
            subPathList = new ObservableCollection<string>();
        }

        public ISourceControlBasePath BasePath
        {
            get { return basePath; }
            set
            {
                basePath = value;
                NotifyPropertyChange("BasePath");
            }
        }

        public ObservableCollection<string> SubPathList
        {
            get { return subPathList; }
            set
            {
                subPathList = value;
                NotifyPropertyChange("SubPathList");
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        ISourceControlBasePath ISourceControlFilter.BasePath
        {
            get { return basePath; }
            set { }
        }


        public void SubPathListChanged()
        {
            NotifyPropertyChange("SubPathList");
        }

        private void NotifyPropertyChange(string property)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(property));
            }
        }
    }
}